<?php

namespace app\components;


use app\exception\ErrorCode;
use app\exception\OaException;
use yii\validators\Validator;

class GoodsValidator extends Validator
{

    public function validateAttribute($model, $attribute)
    {
        $value = $model->$attribute;
        if (!is_array($value)) throw new OaException(ErrorCode::PARMA_ERROR);
        foreach ($value as $r) {
            if (empty($r["num"]) || empty($r["goodsId"]) || $r["num"] == 0 || $r["goodsId"] == 0) {
                throw new OaException(ErrorCode::PARMA_ERROR);
            }
        }


    }
}